package com.app.micaihu.view.user.userinfo;

import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

import com.app.micaihu.R;
import com.app.micaihu.bean.interactive.IDefriend;
import com.app.micaihu.utils.InteractiveUtils;
import com.app.utils.util.view.DrawableLeftTextCenterTextView;

/**
 * Created by Guo on 2016/12/27.
 * <p>
 * <p>
 * 黑名单 按钮
 */

public class DefriendView extends DrawableLeftTextCenterTextView implements View.OnClickListener {


    private IDefriend iDefriend;

    public DefriendView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView();
    }

    public DefriendView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DefriendView(Context context) {
        this(context, null);
    }


    private void initView() {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.common_font_size11));
        setBackgroundResource(R.drawable.attention_fans_btn_bg);
        setTextColor(getResources().getColorStateList(R.color.gray_to_green));
        setGravity(Gravity.CENTER);
        //设置间距
        int padding = (int) getResources().getDimension(R.dimen.dp_5);
        setPadding(0, padding, 0, padding);

    }


    @Override
    public void setTag(Object tag) {
        super.setTag(tag);
        if (tag != null && tag instanceof IDefriend) {
            this.iDefriend = (IDefriend) tag;
            this.setOnClickListener(this);
        }
        if (this.iDefriend != null) {
            flushStatus(this.iDefriend.getIInBlacklist());
        }
    }


    /**
     * 刷新当前View 的状态
     *
     * @param status
     */
    public void flushStatus(boolean status) {
        if (status) {
            this.setSelected(true);
            this.setText(getResources().getString(R.string.common_inBlacklist));
        } else {
            this.setSelected(false);
            this.setText(getResources().getString(R.string.common_unBlacklist));
        }


    }


    @Override
    public void onClick(View v) {
        if (this.iDefriend == null) return;
        InteractiveUtils.getInstance().defriend(v.getContext(), this.iDefriend, (DefriendView) v);
    }

}
